import * as Cesium from 'cesium';
import * as turf from '@turf/turf';
import PolylineTrainMaterialProperty from './material/PolylineTrainMaterialProperty';

export default class RectFlyLight {
  constructor(viewer) {
    // 设置矩形区域[以广州塔为中心，将经纬度 各自加减0.05形成一个矩形区域]
    this.bbox = [113.2691, 23.014, 113.3691, 23.159];
    //创建随机点
    const points = turf.randomPoint(300, {
      bbox: this.bbox,
    });
    console.log(points);
    // 通过生成的随机点，生成对应的折线【线段】
    const features = points.features;
    features.forEach((item) => {
      // 获取 点的经纬度
      const point = item.geometry.coordinates;
      // 根据点 设置起始位置
      const start = Cesium.Cartesian3.fromDegrees(point[0], point[1], 0);
      // 根据点 设置终止位置
      const end = Cesium.Cartesian3.fromDegrees(
        point[0],
        point[1],
        200 + Math.random() * 3000
      );
      // 创建自定义材质
      const polylineTrainMaterialProperty = new PolylineTrainMaterialProperty();
      // 设置折线
      const line = viewer.entities.add({
        polyline: {
          positions: [start, end],
          width: 2,
          material: polylineTrainMaterialProperty,
        },
      });
    });
  }
}
